﻿using MySql.Data.MySqlClient;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace Dao
{
    /// <summary>
    /// 一个业务只能用一种框架，否则会有事务问题，谨慎使用
    /// </summary>
    public static class DB
    {
        /// <summary>
        /// orm框架PetaPoco   https://blog.csdn.net/loong_king2014/article/details/53605793
        /// </summary>
        public static Database MySqlDbPetaPoco
        {
            get
            {
                MySqlConnection connection = new MySqlConnection(Common.AppSettings.AppSetting("connString"));
                connection.Open();
                Database db = new Database(connection);
                return db;
            }
        }
        /// <summary>
        ///  推荐使用 orm框架SqlSugar  文档 http://www.codeisbug.com/Doc/8
        /// </summary>
        public static SqlSugarClient MySqlDbSqlSugar
        {
            get
            {
                SqlSugarClient db = new SqlSugarClient(
                 new ConnectionConfig()
                 {
                     ConnectionString = Common.AppSettings.AppSetting("connString"),
                     DbType = DbType.MySql,//设置数据库类型
                     IsAutoCloseConnection = true,//自动释放数据务，如果存在事务，在事务结束后释放
                     InitKeyType = InitKeyType.SystemTable //从实体特性中读取主键自增列信息
                 });
                return db;
            }
        }
    }
}
